package com.xuetang9.t9.xinhuaxia.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuetang9.t9.xinhuaxia.beans.User;
import com.xuetang9.t9.xinhuaxia.mappers.UserMapper;
import com.xuetang9.t9.xinhuaxia.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 李亚奇
 * @version 1.0
 * @desc TODO
 * @date 2020/2/26 10:35
 * @copyright liyq
 * @address 成都西部国际金融中心2栋2201
 **/
@Service
public class UserService implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean insertUser(User user) {
        return userMapper.insertSelective(user)>0;
    }

    @Override
    public boolean removeUser(Long userId) {
        return userMapper.deleteByPrimaryKey(userId)>0;
    }

    @Override
    public boolean updateUser(User user) {
        return userMapper.updateByPrimaryKeySelective(user)>0;
    }

    @Override
    public User queryById(Long userId) {
        return userMapper.queryByUserId(userId);
    }

    @Override
    public User login(String username, String password) {
        return  userMapper.logion(username,password);
    }

    @Override
    public PageInfo<User> queryByPage(int currentPage, int perPageSize) {
        PageHelper.startPage(currentPage,perPageSize);
        PageHelper.orderBy("u_userId desc");
        List<User> users = userMapper.selectAll();
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return pageInfo;
    }

    @Override
    public boolean queryByUserName(User user) {
        return userMapper.selectCount(user)>0;
    }
}
